<template>
  <div class="checkPlan_box">
    <div class="checkPlan_top">
      <div class="checkPlan_title">订单利润排行</div>
    </div>

    <div v-if="cause&&cause.length>0" class="echarts_container">
      <div id="reasonOrder" class="col-md-12  col-sm-12 col-xs-12" style="height: 100%;" />
    </div>
    <div v-else class="echarts_noData">
      <svg-icon icon-class="暂无数据" />
    </div>
  </div>
</template>

<script>
import { profit } from '@/api/receivableAndPayable/receivableAndPayableManage/receivableBoard'
import { mapGetters } from 'vuex'
export default {
  name: 'LocationDistribution',
  computed: {
    ...mapGetters([
      'windowResizeTag'
    ])
  },
  watch: {
    windowResizeTag() {
      if (this.myChart) {
        this.$nextTick(() => {
          setTimeout(() => {
            this.drawLine()
          }, 500)
        })
      }
    }
  },
  data() {
    return {
      msg: 'fafa',
      cause: ['1'],
      value: '1',
      myChart: undefined,
      myVertical: undefined,
      timer: undefined
    }
  },
  beforeDestroy() {
    // 页面关闭清除定时器
    clearInterval(this.timer)
  },
  mounted() {
    this.getList()
    this.timer = setInterval(() => {
      this.getList()
    }, this.$store.state.common.refreshFrequency * 1000)
  },
  methods: {
    getList() {
      profit().then(res => {
        this.cause = res.data
        this.drawLine()
      })
    },
    drawLine() {
      const causeOne = this.cause
      this.$echarts.init(document.getElementById('reasonOrder')).dispose()
      this.myChart = this.$echarts.init(document.getElementById('reasonOrder'))
      this.myChart.setOption({
        grid: {
          show: false,
          top: '20',
          right: '20',
          bottom: '40',
          left: '80'
        },
        tooltip: {
          trigger: 'axis',
          padding: [12, 17, 20, 23],
          textStyle: { color: '#333' },
          axisPointer: {
            type: 'shadow'
          },
          formatter: function(params) {
            return params[0].name + '<br />' + "<span style='display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:#836AA8'></span>" + params[0].value
          }
        },
        color: ['#836AA8'],
        xAxis: {
          type: 'category',
          data: causeOne.map(item => item.saleOrderCode),
          axisTick: {
            show: false
          },
          axisLabel: {
            show: true,
            color: '#999999', // 更改坐标轴文字颜色
            textStyle: {
              fontSize: 12 // 更改坐标轴文字大小
            }
          },
          axisLine: {
            show: false
          }
        },
        yAxis: {
          type: 'value',
          // 影藏y轴刻度
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisLabel: {
            show: true,
            color: '#999999', // 更改坐标轴文字颜色
            textStyle: {
              fontSize: 12 // 更改坐标轴文字大小
            },
            margin: 20
          }
        },
        series: [
          {
            data: causeOne.map(item => item.profit),
            silent: true,
            type: 'bar',
            itemStyle: {
              normal: {
                // color: '#FF9ADC',
                barBorderRadius: [20, 20, 0, 0]
                // shadowColor: 'rgba(0, 0, 0, 0.3)',
                // shadowOffsetX: 2, // 折线的X偏移
                // shadowOffsetY: 0, // 折线的Y偏移
                // shadowBlur: 6 // 折线模糊
              }
            },
            barWidth: 12 // 柱图宽度
          }
        ]
      })
    }
  }
}
</script>

<style lang="less" scoped>
.checkPlan_box{
  width: 100%;
  height: calc(100% - 50px);
}
.checkPlan_top {
  display: flex;
  justify-content: space-between;

  .checkPlan_title {
    font-size: 20px;
    font-weight: bold;
    line-height: 34px;
    letter-spacing: -0.21px;
    color: #333333;
    padding-top: 16px;
    padding-left: 20px;
  }

  .checkPlan_month{
    padding-top: 16px;
    padding-right: 20px;
  }
}
</style>
